const app = getApp();
const req = require('../../../utils/token.js');
Component({
  options: {
    addGlobalClass: true,
    multipleSlots: true,
  },
  properties: {
    flag: {
      type: String,//类型
      value: '0'//默认值
    },
    ShowModal: { //是否显示整个modal框
      type: Boolean,
      value: false
    },
    isShowTitle: { // 是否显示标题
      type: Boolean,
      value: true
    },
    modalTitle: { // 标题内容
      type: String,
      value: "标题"
    },
    placeholder: { // input框提示文字
      type: String,
      value: "请输入提示文字"
    },
    showDesc: { // 备注文字
      type: String,
      value: ""
    },
    inputType: { // input框类型
      type: String,
      value: 'text'
    },
    isShowInput: { // 是否显示 input框
      type: Boolean,
      value: true
    },
    inputVal: {
      type: [String, Number],
      value: ''
    }
  },
  data: {
    isfous: false,
    flag:0,
    replace:0,
  },
  methods: {
    formSubmit: function (e) {
    var that=  this.data
      var remake =null;  // 车？票
      var reDate=null;    //商场地址
      var url='';
      let { ticketRequestFee, messageContent, messageContentCar} = e.detail.value;
      if (that.flag == 0){
        if (ticketRequestFee == null || ticketRequestFee==''){
          wx.showToast({
            title: '小费不能为空',
            icon: "none",
            duration: 1000
          })
          return
        }
        if (messageContent == null || messageContent == '') {
          wx.showToast({
            title: '备注不能为空',
            icon: "none",
            duration: 1000
          })
          return
        }
      } else if (that.flag == 1){
        if (messageContentCar == null || messageContentCar == '') {
          wx.showToast({
            title: '备注不能为空',
            icon: "none",
            duration: 1000
          })
          return
        }
      }
      var appredate = app.globalData.marketinfo;
      reDate={
              marketId: appredate.marketId,
              marketName: appredate.marketName,
              detailed: appredate.detailed,
              province: appredate.province,
              city: appredate.city,
              district: appredate.district,
              address: appredate.address,
              leftOneX: appredate.longitude,
              leftOneY: appredate.latitude,
              createUser: app.globalData.userInfo.uuid,
      }
      if (that.flag==0){
        url ="ticket/ticketInfoInsert";
            remake = {
              marketId: appredate.marketId,
              ticketRequestFee: ticketRequestFee,
              remarks: messageContent,
              parketRequestOwner: app.globalData.userInfo.uuid,
              currentLocation: appredate.marketName,
              createUser: app.globalData.userInfo.uuid,
              ticketOwner: app.globalData.userInfo.uuid,
            }
      }else{
        url = "park/parkInfoInsert";
        remake = {
          marketId: appredate.marketId,
          // messageId: app.globalData.userInfo.uuid,
          parketRequestOwner: app.globalData.userInfo.uuid,
          currentLocation: appredate.marketName,
          createUser: app.globalData.userInfo.uuid,
          remarks:messageContentCar,
        }
      }
      
      var header = req.CreateHeader();
      var title = '';
      var _this= this;
      wx.request({
        url: app.globalData.url + "marketInfo/instMarketInfo",
        header: header,
        data: reDate,
          success: function (res) {
              if(res.data){
                wx.request({
                  url: app.globalData.url + url,
                  header: header,
                  data: remake,
                  success: function (res) {
                    console.log(res)
                    if (res.statusCode == '200' && res.data != '9999' && res.data != false && res.data != null) {
                      wx.showToast({
                        title: '发布成功',
                        icon: 'success',
                        duration: 1000
                      })
                      _this.triggerEvent('onLoad', 1, 2) 
                      _this.setData({
                        ShowModal: false
                      })
                      return true
                    }else{
                      wx.showToast({
                        title: '发布失败',
                        icon: 'noon',
                        duration: 1000
                      })
                    }
                  },
                  fail:function(res){
                    wx.showToast({
                      title: '发布失败!请重试',
                      icon: 'noon',
                      duration: 1000
                    })
                  }
                })
              }
            },
            fail:function(res){
              wx.showToast({
                title: '发布失败!请重试',
                icon: 'noon',
                duration: 1000
              })
            }
      })
      
    },
    bindFous() {
      console.log(1)
      this.setData({
        isfous: true
      })
    },
    bindBlur() {
      console.log(2)
      this.setData({
        isfous: false
      })
    },
    _bindInput(e) {
      console.log(3)
      this.triggerEvent('customBindInput', e.detail.value)
    },
    cancle() {
      console.log(4)
      this.triggerEvent('cancle')
    },
    _confirm(e) {
      console.log(5)
      this.triggerEvent("confirm");
    },
    switchColor: function (e) {
      console.log(e.currentTarget.id);
      this.setData({
        flag: e.currentTarget.id
      })
    },
    exit: function () {
      this.setData({
        ShowModal: false
      })
      this.triggerEvent('geocoder', 1, 2) 
    },
    handleInput(e) {//数字验证
      this.setData({
        replace:0,
      })
      let ticketRequestFee = this.validateNumber(e.detail.value)
      this.setData({
        ticketRequestFee
      })
    },
    validateNumber(val) {//数字验证
       return val.replace(/\D/g, "")
    },
    cancle(){
      console.log("2")
    }
   
  },
})
